/**
 * @file
 * @author
 * @date
 * @brief
 */
#ifndef DISPLAY_INTERFACE_240X240_H_
#define DISPLAY_INTERFACE_240X240_H_
#include "arabic_reshaper.h"
#include "display_ctrl.h"
#include "display_drv.h"
#include "little_fs.h"
#include "localize_string.h"
#include "stdint.h"
#include "utf8_to_unicode.h"
#include <wchar.h>
#define FONT_SIZE_HORIZ_INTERVAL (2)    //字与字之间水平间隔
#define FONT_SIZE_VERTICAL_INTERVAL (4) //段落间隔

//圆环参数
typedef struct
{
    uint8_t state; // 1~4区域 0=无效
    uint8_t r1;    //内径
    uint8_t r2;    //外径
    uint8_t centre_x;
    uint8_t centre_y;
    uint8_t target_y1;
    uint8_t target_y2;
    float cot_angle;
} annulus_cfg_t;

//组合型刷动态图的接口参数
typedef struct
{
    int img_sn_full;
    uint8_t img_x;
    uint8_t img_y;
    uint8_t img_sub_cnt;
    int img_sub_sn[4];
    uint8_t img1_x;
    uint8_t img1_y;
    uint8_t img1_w;
    uint8_t img1_h;
    uint16_t reflash_ms;
} show_com_img_cfg_t;

typedef struct
{
    int img1_sn;
    uint8_t img1_x;
    uint8_t img1_y;
    int img2_sn;
    uint8_t img2_x;
    uint8_t img2_y;
} img2_cfg_t;

typedef struct
{
    int bg_sn;
    uint8_t gif_count;
    struct
    {
        uint8_t x;
        uint8_t y;
        int sn;
    } img[5];
} img_gif_com_t;

//显示大数字的类型
typedef enum
{
    DISP_NUM_TYPE_LEFT,
    DISP_NUM_TYPE_MID,
    DISP_NUM_TYPE_RIGHT,
} disp_num_type_t;

uint8_t get_num_digit(int num);
//
//居中显示字符串
void disp_show_font_string_utf8_mid(uint8_t y, const char *str, uint8_t reserve_size);

//画图
void disp_draw_user_image(int16_t x, int16_t y, const uint8_t *p_user_image);
void disp_draw_user_image_ignore_color(int16_t x, int16_t y, uint16_t ignore_color, const uint8_t *p_user_image);
void disp_draw_user_image_gray(int16_t x, int16_t y, uint16_t color, const unsigned char *p_user_image);
void disp_draw_user_image_gray_lucency(int16_t x, int16_t y, uint16_t color, const unsigned char *p_user_image);
void disp_draw_user_image_num_mid_gray_lucency(int16_t x, int16_t y, uint16_t color, uint32_t num, uint8_t width, const unsigned char *const IMAGE_USER_NUM_TAB[]);
void _disp_show_num_extend(disp_num_type_t type, uint8_t x, uint8_t y, uint32_t num, uint8_t width, const uint8_t *const IMAGE_USER_NUM_TAB[]);
void _disp_show_num_color_extend(disp_num_type_t type, uint8_t x, uint8_t y, uint32_t num, uint8_t width, uint16_t color, const uint8_t *const IMAGE_USER_NUM_TAB[]);

void disp_draw_user_image_num_mid_gray_lucency_ignore(int16_t x, int16_t y, uint16_t ignore_color, uint32_t num, uint8_t width, const unsigned char *const IMAGE_USER_NUM_TAB[]);
int disp_draw_user_image_num_mid_ignore(int16_t x, int16_t y, uint16_t ignore_color, uint32_t num, uint8_t width, const unsigned char *const IMAGE_USER_NUM_TAB[]);
int disp_draw_user_image_num_mid_filter_color(int16_t x, int16_t y, uint32_t num, uint8_t width, const unsigned char *const IMAGE_USER_NUM_TAB[]);
int disp_draw_user_image_num_right_align_filter_color(int16_t x, int16_t y, int32_t num, int interval, const unsigned char *const IMAGE_USER_NUM_TAB[]);
void disp_draw_user_image_lucency_ignore(int16_t x, int16_t y, uint16_t ignore_color, const unsigned char *p_user_image);
void disp_draw_user_image_half_lucency_ignore(int16_t x, int16_t y, uint16_t ignore_color, const unsigned char *p_user_image);

void disp_draw_img_rotate(const unsigned char *p_image, uint16_t ignore_color, uint32_t centre_xy, uint32_t centre_set_xy, uint16_t degree);

void disp_draw_user_image_bg_color(int16_t x, int16_t y, uint16_t ignore_color, const uint8_t *p_user_image);

//画点
void disp_draw_point(disp_xy_t x, disp_xy_t y, uint16_t color);

//颜色调整
void disp_draw_image_gradual_change_t_2_b(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint16_t start_color, uint16_t end_color, uint16_t ignore_color);
void disp_draw_image_gradual_change_lb_2_rt(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint16_t start_color, uint16_t end_color);
void disp_draw_rect_color_mixture(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint16_t alpha);
void disp_draw_image_gradual_fill_t_2_b(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint16_t start_color, uint16_t end_color, uint16_t ignore_color);

//画图形
void disp_draw_rect_color(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint16_t color);
void disp_draw_image_gradual_lb_2_rt_line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint16_t start_color, uint16_t end_color);
void disp_draw_image_gradual_change_lb_2_rt_line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint16_t start_color, uint16_t end_color);

//画外部flash图片的接口
void _disp_show_flash_img(uint8_t file_index, uint8_t start_x, uint8_t start_y, int img_sn);

//画flash内的圆环
void disp_annulus_calc(uint16_t degree, annulus_cfg_t *p_cfg);
void disp_draw_flash_image_annulus(int16_t x, int16_t y, uint16_t ignore_color, uint16_t img_w, uint16_t img_h, lfs_file_t *p_file, annulus_cfg_t *p_annulus_cfg);

void disp_show_font_string_utf8(uint8_t x, uint8_t y, const char *str, uint8_t reserve_size);
void disp_show_font16_string_utf8(uint8_t x, uint8_t y, const char *str, uint16_t color);
uint32_t disp_show_font_string(int x1, int y1, int x2, int y2, uint16_t const *unicode_str, uint16_t reserve_size, int16_t *align_type);
int disp_show_font_string_page_cal(int x1, int y1, int x2, int y2, uint16_t const *unicode_str, uint16_t reserve_size);
void disp_show_ascii_string(uint8_t x, uint8_t y, char *p_str, uint8_t size, uint16_t color);
int disp_calc_start_x(disp_num_type_t type, int x, const char *p_string, int size);
int disp_calc_font_string_start_x(disp_num_type_t type, int x, const char *p_string, int size);

//特殊接口，给某些特定界面特制的接口
void disp_draw_hr_line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
void disp_draw_gps_locus_line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);

void disp_draw_heart_rate_rect_filter_color(int start_x, int end_x, uint8_t *y_data, uint16_t line_color, uint16_t rect_color, uint16_t bottom_y);

//----组合型画图接口----
void _disp_show_com_img(show_com_img_cfg_t *p_cfg);
void _disp_show_flash_img_gif(const img_gif_com_t *p_cfg, int refresh_interval_ms);
void _disp_show_flash_img_gif_56_56(const img_gif_com_t *p_cfg, int refresh_interval_ms);
void _disp_show_flash_img_gif_100(const img_gif_com_t *p_cfg, int refresh_interval_ms);
void _disp_show_flash_img_gif_100_mid(const img_gif_com_t *p_cfg, int refresh_interval_ms);

void disp_draw_user_image_filter_color(int16_t x, int16_t y, const uint8_t *p_user_image);
void disp_draw_user_image_filter_color_gray_lucency(int16_t x, int16_t y, const uint8_t *p_user_image, uint16_t color);
void disp_draw_user_image_over_y(int16_t x, int16_t y, const uint8_t *p_user_image, int y_base);
void disp_draw_user_image_less_x(int16_t x, int16_t y, const uint8_t *p_user_image, int x_base);

void disp_draw_user_image_percent_circle(int x, int y, uint8_t const *p_user_image, int percent, int inner_diameter);
int disp_draw_user_image_num(int x, int y, int num, int width, uint8_t const *const *num_image);
int disp_draw_user_image_num_filter_color(int x, int y, int num, int width, uint8_t const *const *num_image);
int disp_draw_user_image_num_multiply(int x, int y, int num, int width, uint8_t const *const *num_image);

int disp_draw_user_image_num_with_digits(int x, int y, int num, int digits, int font_width, uint8_t const *const *num_image);
int disp_draw_user_image_num_with_digits_gray_lucency(int x, int y, int num, int digits, uint16_t color, int font_width, uint8_t const *const *num_image);
int disp_draw_user_image_num_with_digits_filter_color(int x, int y, int num, int digits, int font_width, uint8_t const *const *num_image);
int disp_draw_user_image_num_with_digits_multiply(int x, int y, int num, int digits, int font_width, uint8_t const *const *num_image);
void _disp_show_flash_img_gif_all(const img_gif_com_t *p_cfg, uint8_t file_index);

typedef struct __user_cycle_percent_param_t
{
    uint8_t const *base;
    uint16_t transparent_color;
    uint16_t full_color;
    uint16_t empty_color;
    int x;
    int y;
    int target_num;
    int presently_num;
    int *temp_0;
    int *temp_1;
    float *temp_2;
    int *temp_3;
    int *temp_4;
    int line_width;
} user_cycle_percent_param_t;
void disp_draw_user_image_cycle_percent(user_cycle_percent_param_t const *param);
// typedef struct __flash_cycle_percent_param_t
// {
//     int file_index;
//     int x;
//     int y;
//     int file_sn;
//     int target_num;
//     int presently_num;
//     int *temp_0;
//     int *temp_1;
// } flash_cycle_percent_param_t;
// void disp_draw_flash_image_cycle_percent(flash_cycle_percent_param_t const *param);

// typedef struct __draw_flash_radian_cycle_param_t
// {
//     int file_index;
//     int x; //!<绘制到屏幕的坐标
//     int y;
//     int center_x; //!< 相对坐标
//     int center_y;
//     float inner_diameter;    //!< 内径
//     float external_diameter; //!< 外径
//     float start_radian;      //!闭区间
//     float end_radian;        //!闭区间
//     int transparent_color;
//     int *temp_0;
//     int *temp_1;
// } draw_flash_radian_cycle_param_t;
// void disp_draw_flash_radian_cycle(draw_flash_radian_cycle_param_t const *param);

// typedef struct __draw_radian_cycle_param_t
// {
//     uint16_t color;
//     uint16_t second_color;
//     int x; //!<绘制到屏幕的坐标
//     int y;
//     int center_x; //!< 相对坐标
//     int center_y;
//     float inner_diameter;    //!< 内径
//     float external_diameter; //!< 外径
//     float start_radian;      //!闭区间
//     float end_radian;        //!闭区间
// } draw_radian_cycle_param_t;
// void disp_radian_cycle(draw_radian_cycle_param_t const *param);

void disp_show_user_string_middle(uint8_t start_x, int width, uint8_t start_y, char *p_string, uint8_t const *(*get_bmp)(char c));

int disp_draw_user_image_num_mid_ignore_with_digit(int16_t x, int16_t y, uint16_t ignore_color, uint32_t num, uint8_t width, uint8_t digit, const unsigned char *const IMAGE_USER_NUM_TAB[]);

void disp_show_font_string_utf8_area(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, const char *str, uint8_t reserve_size);

void disp_draw_user_image_transparent(int16_t x, int16_t y, uint16_t color, const unsigned char *p_user_image);
void disp_draw_user_image_transparent_less_x(int16_t x, int16_t y, uint16_t color, const uint8_t *p_user_image, int x_base);
void disp_draw_user_image_transparent(int16_t x, int16_t y, uint16_t color, const unsigned char *p_user_image);
bool disp_show_localize(int disp_little_fs_file_index, int localize_key, int default_temp_index);
bool disp_show_localize_with_x_y(int file_index, int localize_key, int default_temp_index, int x, int y);

void disp_draw_img_rotate_with_solid(const unsigned char *p_image, uint16_t ignore_color, uint32_t centre_xy, uint32_t centre_set_xy, uint16_t degree, int solid_colour, bool transparency_by_white);

void disp_draw_user_image_multiply(int16_t x, int16_t y, const unsigned char *p_user_image);

bool disp_show_resource_with_x_y(int file_index, int key, int default_temp_index, int x, int y);

#endif
